// 云函数入口文件
const cloud = require('wx-server-sdk')

const jwt = require('jsonwebtoken')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const openId = wxContext.OPENID
  const appId = wxContext.APPID;
  const token = jwt.sign({ openId }, '2006A', { expiresIn: '12h' })
  console.log('token:', token)
  return {
    code: 0,
    msg: 'success',
    data: { token }
  }
}